class Person:
    def __init__(self, name):
        self.name = name

    # Getter function
    @property
    def name(self):
        return self._name

    # Setter function
    @name.setter
    def name(self, value):
        if not isinstance(value, str):
            raise TypeError('Expected a string')
        self._name = value

    # Deleter function
    @name.deleter
    def name(self):
        raise AttributeError("Can't delete attribute")


class SubPerson(Person):
    @property
    def name(self):
        print('Getting name')
        return super().name

    @name.setter
    def name(self, value):
        print('Setting name to', value)
        super(SubPerson, SubPerson).name.__set__(self, value)  #为了委托给之前定义的setter方法，需要将控制权传递给之前定义的name属性的 __set__() 方法

    @name.deleter
    def name(self):
        print('Deleting name')
        super(SubPerson, SubPerson).name.__delete__(self)


# 仅仅扩展property的某一个方法
class SubPerson1(Person):
    @Person.name.getter
    def name(self):
        print('Getting name')
        return super().name

    @Person.name.setter
    def name(self, value):
        print('Setting name to', value)
        super(SubPerson, SubPerson).name.__set__(self, value)


if __name__ == '__main__':
    s = SubPerson('Guido')
    print(s.name)
    s.name = 'Larry'
    # s.name = 42
    print('*' * 50)
    s1 = SubPerson1('zhangsan')
    s1.name = 'lisi'
    print(s1.name)
